package com.sduept.nwld.dataserver.rest.daily;

import com.alibaba.fastjson.JSONArray;
import com.sduept.bigdata.document.entity.core.RecordAttachment;
import com.sduept.core.dao.SuperDAO;
import com.sduept.nwld.dataserver.manager.protection.SpecialReportManager;
import com.sduept.nwld.dataserver.model.daily.SpecialReport;
import com.sduept.utils.DateUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Calendar;
import java.util.Date;
import java.util.List;

/**
 * 专项汇报
 */
@RestController
@RequestMapping("/specialReport")
public class SpecialReportService {
	@Autowired
	private SuperDAO dao;
	@Autowired
	private SpecialReportManager sps;
	// 专项汇报

	@GetMapping("/getSpecialReport/{start}/{end}")
	public String getSpecialReport(@PathVariable("start") String start,
			@PathVariable("end") String end) {
		// 序号，专项类型，专项内容，附件，日期
		Date s = DateUtil.getDateByString(start, DateUtil.pattern_ymd);
		Date e = DateUtil.getDateByString(end, DateUtil.pattern_ymd);
		Calendar c = Calendar.getInstance();
		c.setTime(e);
		c.add(Calendar.DAY_OF_YEAR, 1);
		c.add(Calendar.SECOND , -1);
		e = c.getTime();
		String where = " day between ? and ? ";
		List<SpecialReport> report = dao.findByCondition(SpecialReport.class, where,s,e );
		for (SpecialReport a : report) {
			a.setFileNames(dao.findByOid(a.getId(), RecordAttachment.class));
		}
		report = sps.getReportWithUrls(report);
		return JSONArray.toJSONString(report);
	}
}
